package de.homelabs.moonrat.util;

import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;


public class MoonratWebUtils {

	static Logger logger = Logger.getLogger(MoonratWebUtils.class);
	
	public static String getDomainFromRequest(ServletRequest request){
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		try {
			String domain = new URL(httpRequest.getRequestURL().toString()).getHost();
			logger.debug("extracted domain: "+domain);
			return domain;
		} catch (MalformedURLException e) {
			logger.error("can not extract domain: "+e.getMessage());
			return "";
		}
	}
}
